package com.artqiyi.dollmachine.views.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.artqiyi.dollmachine.R;
import com.artqiyi.dollmachine.common.Base.BaseFragment;
import com.artqiyi.dollmachine.common.constant.Constant;
import com.artqiyi.dollmachine.model.entity.UserInfoBean;
import com.artqiyi.dollmachine.presenter.MinePresenter;
import com.artqiyi.dollmachine.utils.manager.ConfigManager;
import com.artqiyi.dollmachine.utils.manager.UserInfoManager;
import com.artqiyi.dollmachine.views.activity.MineCatchRecordActivity;
import com.artqiyi.dollmachine.views.activity.MineDollCoinActivity;
import com.artqiyi.dollmachine.views.activity.MinePayRecordActivity;
import com.artqiyi.dollmachine.views.activity.SettingActivity;
import com.artqiyi.dollmachine.views.activity.WebViewActivity;
import com.artqiyi.dollmachine.views.widget.ToolBarView;
import com.bumptech.glide.Glide;

import butterknife.Bind;
import de.hdodenhof.circleimageview.CircleImageView;
import timber.log.Timber;

/**
 * 我的界面
 */

public class MineFragment extends BaseFragment<MinePresenter> implements View.OnClickListener{
    @Bind(R.id.myCoinLayout)
    LinearLayout myCoinLayout;
    @Bind(R.id.payRecordLayout)
    LinearLayout payRecordLayout;
    @Bind(R.id.couponLayout)
    LinearLayout couponLayout;
    @Bind(R.id.recordLayout)
    LinearLayout recordLayout;
    @Bind(R.id.myDollLayout)
    LinearLayout myDollLayout;
    @Bind(R.id.myOrderLayout)
    LinearLayout myOrderLayout;
    @Bind(R.id.myAddressLayout)
    LinearLayout myAddressLayout;
    @Bind(R.id.inviteLayout)
    LinearLayout inviteLayout;
    @Bind(R.id.settingLayout)
    LinearLayout settingLayout;

    @Bind(R.id.avatarImage)
    CircleImageView avatarImage;

    @Bind(R.id.tvNickName)
    TextView tvNickName;
    @Bind(R.id.tvId)
    TextView tvId;
    @Bind(R.id.tvCoin)
    TextView tvCoin;

    private UserInfoBean mUserInfoBean;

    @Override
    protected MinePresenter getPresenter() {
        return new MinePresenter();
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_mine;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        myCoinLayout.setOnClickListener(this);
        payRecordLayout.setOnClickListener(this);
        couponLayout.setOnClickListener(this);
        recordLayout.setOnClickListener(this);
        myDollLayout.setOnClickListener(this);
        myOrderLayout.setOnClickListener(this);
        myAddressLayout.setOnClickListener(this);
        inviteLayout.setOnClickListener(this);
        settingLayout.setOnClickListener(this);
        myCoinLayout.setVisibility(ConfigManager.getInstance().getClosePay()?View.GONE:View.VISIBLE);
        payRecordLayout.setVisibility(ConfigManager.getInstance().getClosePay()?View.GONE:View.VISIBLE);
        mUserInfoBean = UserInfoManager.getInstance().getUserInfoBean();
        if (mUserInfoBean != null) {
            tvNickName.setText(mUserInfoBean.getNickname());
            tvId.setText(String.format(getString(R.string.mine_id), String.valueOf(mUserInfoBean.getId())));
            Glide.with(getActivity()).load(mUserInfoBean.getAvatar()).into(avatarImage);
        }
    }

    @Override
    protected void handleToolBar(ToolBarView toolBar) {
        super.handleToolBar(toolBar);
        toolBar.setVisibility(View.GONE);
    }

    @Override
    public void reLoadData() {
        super.reLoadData();
        tvCoin.setText(String.valueOf(UserInfoManager.getInstance().getUserInfoBean().getCoin()));
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.myCoinLayout:
                startActivity(new Intent(getActivity(), MineDollCoinActivity.class));
                break;
            case R.id.couponLayout:

                break;
            case R.id.payRecordLayout:
                startActivity(new Intent(getActivity(), MinePayRecordActivity.class));
                break;
            case R.id.recordLayout:
                startActivity(new Intent(getActivity(), MineCatchRecordActivity.class));
                break;
            case R.id.myDollLayout:
                startActivity(new Intent(getActivity(), WebViewActivity.class).putExtra(Constant.KEY_MINE_WEBVIEW_TYPE, Constant.MINE_MYWAWA));
                break;
            case R.id.myOrderLayout:
                startActivity(new Intent(getActivity(), WebViewActivity.class).putExtra(Constant.KEY_MINE_WEBVIEW_TYPE, Constant.MINE_ORDER));
                break;
            case R.id.myAddressLayout:
                startActivity(new Intent(getActivity(), WebViewActivity.class).putExtra(Constant.KEY_MINE_WEBVIEW_TYPE, Constant.MINE_ADDRESS));
                break;
            case R.id.inviteLayout:

                break;
            case R.id.settingLayout:
                startActivity(new Intent(getActivity(), SettingActivity.class));
                break;
            default:
                break;
        }
    }
}
